
package com.netease.xone.activity;

import android.content.Context;
import android.content.Intent;
import android.os.Build;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentTransaction;
import android.widget.LinearLayout;

import com.actionbarsherlock.view.Window;
import com.netease.pkgRelated.XoneConsts.BUNDLE_KEY;
import com.netease.xone.R;
import com.netease.xone.fragment.FragUpdateApp;

public class ActivityUpdateApp extends ActivityX1Base {

    public static void lunch(Context context, String url, String content, String version) {
        Intent intent = new Intent(context, ActivityUpdateApp.class);
        intent.putExtra(BUNDLE_KEY.UPDATE_CONTENT, content);
        intent.putExtra(BUNDLE_KEY.UPDATE_URL, url);
        intent.putExtra(BUNDLE_KEY.UPDATE_VERSION, version);
        context.startActivity(intent);
    }
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        LinearLayout linear = new LinearLayout(this);
        linear.setId(R.id.activity_updateapp_container_id);
        LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(
                LinearLayout.LayoutParams.MATCH_PARENT,
                LinearLayout.LayoutParams.MATCH_PARENT);
        linear.setLayoutParams(lp);
        setContentView(linear);
        Intent intent = getIntent();
        String version = null;
        if(intent != null) {
            version = intent.getStringExtra(BUNDLE_KEY.UPDATE_VERSION);
        }
        if(version == null ){
            finish();
            return;
        }
        if (findViewById(R.id.activity_updateapp_container_id) != null
                && savedInstanceState == null) {
            FragmentManager fm = getSupportFragmentManager();
            FragmentTransaction ft = fm.beginTransaction();
            Fragment fragment = new FragUpdateApp();
            ft.add(R.id.activity_updateapp_container_id, fragment);
            ft.commit();
        }
        if(Build.VERSION.SDK_INT >= 11){
            setFinishOnTouchOutside(false);
        }
    }

    @Override
    protected void requestFeature() {
        requestWindowFeature(Window.FEATURE_NO_TITLE);
    }
}
